package com.easy.modules.sysmgr.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import com.easy.modules.common.RecordEntity;

/**
 * 员工信息基本表
 * 创建者： 杨浩泉
 * 创建时间： 2014-3-17 下午9:20:27
 * 版本号： v1.0
 */
@Entity
@Table(name = "EASY_SYSMGR_USER")
@DynamicUpdate(true)
@DynamicInsert(true)
public class UserEntity extends RecordEntity {

	private String num ;						//员工编号
	
	private String account ;					//登录账号
	
	private String password ;					//登录密码
	
	private Integer status = new Integer(0);	//账号状态（0：允许登录，1：禁止登录）
	
	private Integer del = new Integer(0) ;		//非物理删除（0：否，1：是）
	
	private String lastAcceccTime ;				//最后访问时间
	
	private String truename ;					//真实姓名

	private String sex ;						//性别
	
	private String email ;						//邮箱地址
	
	private String mobile ;						//手机号码
	
	private DeptEntity dept ;					//用户所属部门
	
	private CompanyEntity company ;				//用户隶属公司
	
	private PositionEntity position ;			//职位、岗位
	
	private Set<PermitsEntity> permits = new HashSet<PermitsEntity>(0) ;						//权限组
	
	private Set<UserWorkGroupEntity> workgroups = new HashSet<UserWorkGroupEntity>(0) ;			//用户工作组
	
	private Set<UserRoleEntity> userroles = new HashSet<UserRoleEntity>(0) ;					//用户角色
	
	private Set<ScheduleEntity> schedules = new HashSet<ScheduleEntity>(0) ;					//日程
	
	@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
	@OrderBy("created desc")
	public Set<ScheduleEntity> getSchedules() {
		return schedules;
	}

	public void setSchedules(Set<ScheduleEntity> schedules) {
		this.schedules = schedules;
	}

	@ManyToOne
	@JoinColumn(name = "POSITION_ID")
	public PositionEntity getPosition() {
		return position;
	}

	public void setPosition(PositionEntity position) {
		this.position = position;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "EASY_SYSMGR_USER_WORKGROUP", joinColumns = { @JoinColumn(name = "USER_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "WORKGROUP_ID", nullable = false, updatable = false) })
	public Set<UserWorkGroupEntity> getWorkgroups() {
		return workgroups;
	}

	public void setWorkgroups(Set<UserWorkGroupEntity> workgroups) {
		this.workgroups = workgroups;
	}

	

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "EASY_SYSMGR_USER_USERROLE", joinColumns = { @JoinColumn(name = "USER_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "USERROLE_ID", nullable = false, updatable = false) })
	public Set<UserRoleEntity> getUserroles() {
		return userroles;
	}
	
	public void setUserroles(Set<UserRoleEntity> userroles) {
		this.userroles = userroles;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "EASY_SYSMGR_USER_PERMITS", joinColumns = { @JoinColumn(name = "USER_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "PERMITS_ID", nullable = false, updatable = false) })
	public Set<PermitsEntity> getPermits() {
		return permits;
	}

	public void setPermits(Set<PermitsEntity> permits) {
		this.permits = permits;
	}

	@ManyToOne
	@JoinColumn(name="DEPT_ID")
	public DeptEntity getDept() {
		return dept;
	}

	public void setDept(DeptEntity dept) {
		this.dept = dept;
	}

	@ManyToOne
	@JoinColumn(name="COMPANY_ID")
	public CompanyEntity getCompany() {
		return company;
	}

	public void setCompany(CompanyEntity company) {
		this.company = company;
	}

	public String getNum() {
		return num;
	}

	public void setNum(String num) {
		this.num = num;
	}


	public String getLastAcceccTime() {
		return lastAcceccTime;
	}

	public void setLastAcceccTime(String lastAcceccTime) {
		this.lastAcceccTime = lastAcceccTime;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getTruename() {
		return truename;
	}

	public void setTruename(String truename) {
		this.truename = truename;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Integer getDel() {
		return del;
	}

	public void setDel(Integer del) {
		this.del = del;
	}

}
